package com.example.mynote.ui.clock;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

/**
 * MySqliteOpenHelper 工具类 （1.构造函数私有化  2.对外提供函数）
 */
public class MySqliteOpenHelper extends SQLiteOpenHelper {

    private static SQLiteOpenHelper mInstance;

    /**
     * 对外提供函数 单例模式
     */
    public static synchronized SQLiteOpenHelper getmInstance(Context context)
    {
        if(mInstance == null){
            mInstance = new com.example.mynote.ui.clock.MySqliteOpenHelper(context, "myDB.db", null, 1);
        }
        return mInstance;
    }

    /**
     * 构造函数私有化
     */
    private MySqliteOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    /**
     * 数据库初始化
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table clock(_id integer primary key autoincrement, hour integer , minute integer ,  selected integer, remark text);";
        db.execSQL(sql);

    }

    /**
     * 数据库升级
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
